﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Krile.Kernel.WindowsEx;

namespace Krile.Forms.Dialogs.Show
{
    public partial class ExceptionTracking : Form
    {
        public ExceptionTracking(Exception e)
        {
            InitializeComponent();
            ErrorIcon.Image = SystemIcons.Error.ToBitmap();
            DetailDesctiption.Text = e.ToString();
        }

        private void DoCopy_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Clipboard.SetText(DetailDesctiption.Text);
            MessageBoxEx.Show("Copyed.", "Copy error detail",
                              MessageBoxEx.MessageBoxExButtons.Close, MessageBoxEx.MessageBoxExIcon.Information);
        }

        private void Report_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (!String.IsNullOrEmpty(Define.DebugAgentFileName) && File.Exists(Path.Combine(Application.StartupPath, Define.DebugAgentFileName)))
            {
                var path = System.IO.Path.Combine(Application.StartupPath, System.IO.Path.GetRandomFileName() + ".dbg");
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path))
                {
                    sw.WriteLine(DetailDesctiption.Text);
                    sw.WriteLine("(from Krile v." + Define.VersionString + "-" + Define.Build + ")");
                }
                System.Diagnostics.Process.Start(Path.Combine(Application.StartupPath, Define.DebugAgentFileName), path);
            }
            else
            {
                MessageBoxEx.Show(
                    "Report agent not found.",
                    "You must re-install Krile.", "Feedback error", MessageBoxEx.MessageBoxExButtons.Close, MessageBoxEx.MessageBoxExIcon.Error);
            }
        }
    }
}
